<?php
    session_start();
    $connect = mysql_connect("localhost","root","");

    mysql_select_db("ics_sais_database",$connect);

    if(isset($_POST['login'])){
        $query = mysql_query("SELECT * from admin");
        $array = mysql_fetch_array($query);

        if($_POST['username']==$array[0] && md5($_POST['password'])==$array[3]){

            $_SESSION['uname']=$array[0];
            $_SESSION['pword']=$_POST['password'];
            $_SESSION['role']=$array[1];
            $_SESSION['email']=$array[2];
            $_SESSION['loggin']=1;
            header("location: admin.php");
        }
        else if($_POST['username']!=$array[0]) echo "Username not found";
        else if(md5($_POST['password'])!=$array[3]) echo "Password not found";

    }
    else if(isset($_POST['submit'])){
        switch($_POST['type']){
            case "student":
            $name = $_POST['l_name'].", ".$_POST['f_name']." ".$_POST['m_name'];
            $query = 'INSERT into STUDENT values("'.$_POST['stud_num'].'","'.$_POST['e_add'].'","'.$name.'","no entry","no entry","no entry","no entry","'.$_POST['mob_num'].'","no entry","no entry","no entry","no")';
            $q = mysql_query($query);
            break;
            case "instructor": break;
            case "encoder": break;
        }

    }

    mysql_close($connect);
?>

<html>
<head>
    	<title>ICS SAIS</title>
        
<link href="design.css" rel="stylesheet" type="text/css" />
 
<script type="text/javascript">
	 var RecaptchaOptions = { theme : 'white' };
	
	function form_type_display() {
		disable_all_forms();
		if (document.getElementById('type').value == 'student') {
			var className = 'student_form';
		} else if(document.getElementById('type').value == 'faculty'){
			var className = 'faculty_form';
		} else if(document.getElementById('type').value == 'encoder'){
			var className = 'encoder_form'
		}
		
		<!--get elements by class-->
		<!--http://stackoverflow.com/questions/3808808/how-to-get-element-by-class-in-javascript-->
		var elems = document.getElementsByTagName('*'), i;
		for (i in elems) {
			if((' ' + elems[i].className + ' ').indexOf(' ' + className + ' ')
					> -1) {
				elems[i].style.display = 'table-row';
			}
		}
	}
	
	function disable_all_forms(){
		var elems = document.getElementsByTagName('*'), i;
		var form_names = new Array();
		form_names[0] = 'student_form';
		form_names[1] = 'faculty_form';
		form_names[2] = 'encoder_form';
		for (h in form_names){
			for (i in elems) {
				if((' ' + elems[i].className + ' ').indexOf(' ' + form_names[h] + ' ')
						> -1) {
					elems[i].style.display = 'none';
				}
			}
		}
	}
</script>       

</head>
    
    <body>
   	<div id="cont">
        	<div id="header">
            	<div id="header_main">
                	<div id="mhleft">
                    </div>
                    
                    <div id="mhcenter" ice:editable="*">
                    	<img src="ics_logo_blue.png" id="logo"/>
                      <div id="label_sais">
                        	<div id="border_label">	</div>
                        <div id="label"><p>Students'Academic
Information System</p></div>
                      </div>
                  </div>
                    
                    <div id="mhright">
                    </div>
                </div>
                <div id="bottomhead">
                	<div id="bhleft">
                    </div>
                    <div id="menu_bar">
                    	<!--login-->
                        <form method="post">
                          <table>
                                <tr>	<!--labels-->
                                	<td><label for="username">Username<label/></td>
                                    <td><label for="password">Password<label/></td>
                                    <td></td>
                                </tr>
                                <tr>	<!--forms-->
                                	<td><input type="text" name="username" id="username"/></td>
                                    <td><input type="password" name="password" id="password"/></td>
                                    <td><input type="submit" value="Login" name="login" class="sub_button" /></td>
                                </tr>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
      <div id="body">
      	<div id="body_border">
        </div>
        <div id="announcement">
        </div>
        <div id="sign_up">
            <form name="sign_up" method="post" onClick="form_type_display()" onSubmit="verify.php">
            	<table>
                	<tr>
                    	<td colspan=1><h1>Sign Up</h1></td>
                        <td colspan=1><h1>&nbsp;&nbsp;&nbsp;&nbsp;</h1></td>
                        <td colspan=1><h1>&nbsp;&nbsp;&nbsp;&nbsp;</h1></td>
                    </tr>
                    <tr>
                    	<td colspan=1><label for="type" >User Type</label></td>
                        <td colspan=2><select name="type" id="type" class="sign_up_box" >
                        		<option value="null">-------</option>
                                <option value="student">Student</option>
                                <option value="faculty">Faculty</option>
                                <option value="encoder">Encoder</option>
		                    </select>
                        </td>
                    </tr>
                    <!--Student Forms-->
                    <tr class="student_form" style="display:none">	<!--display: table-row-->
                    	<td colspan=1><label for="stud_num" title="xxxx-xxxxx format">Student Number</label></td>
                        <td colspan=2><input type="text" name="stud_num" id="stud_num" class="sign_up_box" /></td>
                    </tr>
                    <!--insert other forms here class of tr should be "student_form"-->
                    <!--Student Forms-->
                    <!--Faculty Forms-->
                    <tr class="faculty_form" style="display:none">	<!--display: table-row-->
                    	<td colspan=1><label for="emp_num">Employee Number</label></td>
                        <td colspan=2><input type="number" name="emp_num" id="emp_num" class="sign_up_box" min=0 max=99999999 /></td>
                    </tr>
                    <!--insert other forms here class of tr should be "faculty_form"-->
                    <!--Faculty Forms-->
                	<tr>
                    	<td colspan=1><label for="f_name">First Name</label></td>
                        <td colspan=2><input type="text" name="f_name" id="f_name" class="sign_up_box" required/></td>
                    </tr>
                    <tr>
                    	<td colspan=1><label for="l_name">Last Name</label></td>
                        <td colspan=2><input type="text" name="l_name" id="l_name" class="sign_up_box" required/></td>
                    </tr>
                    <tr>
                    	<td colspan=1><label for="m_name">Middle Name</label></td>
                        <td colspan=2><input type="text" name="m_name" id="m_name" class="sign_up_box" required/></td>
                    </tr>
                    <tr>
                    	<td colspan=1><label for="e_add">Email Address</label></td>
                        <td colspan=2><input type="email" name="e_add" id="e_add" class="sign_up_box" required/></td>
                    </tr>
                    <tr>
                    	<td colspan=1><label for="mob_num">Mobile Number</label></td>
                        <td colspan=2><input type="number" title="09xxxxxxxxx" name="mob_num" id="mob_num" class="sign_up_box" required/></td>
                    </tr>
                    
                     <!--reCaptcha-->
					<tr>
                        <td colspan=3><div id="captcha">
                            <?php
                              require_once('recaptchalib.php');
                              $publickey = "6Ld949sSAAAAACjy4uYHNRg4ty1oOZld3MHFF5qF"; // you got this from the signup page
                              echo recaptcha_get_html($publickey);
                            ?>   
                        </div></td>
                    </tr>
                    <!--reCaptcha-->
                   	<tr>
                    	<td colspan=2>
                        	<a href="#"><label title="Request new password via e-mail.">Forgot your password?</label> </a>
                        </td>
                        <td colspan=1>
                        	<input type="submit" name="submit" value="Register" title="Submit account information." class="sub_button" id="register"/>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
      </div>
   	</div>
    </body>
</html>